# -*- coding: utf-8 -*-
'''
author:cooper
date:2012.5.1
类目API:

taobao.itemcats.authorize.get 查询商家被授权品牌列表和类目列表
taobao.itemcats.get 获取后台供卖家发布商品的标准商品类目
taobao.itemprops.get 获取标准商品类目属性
taobao.itempropvalues.get 获取标准类目属性值
taobao.shopcats.list.get 获取前台展示的店铺类目

run every 3 month
'''

#TODO unittest

from TopAPI.lib import *
import json

def Update():
	#TODO 
	pass

class auth_cats():
	api='taobao.itemcats.authorize.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='xinpin_item_cats,item_cats,brands'
		url=getURL(d)
        return getRes(url)
    def parseCat(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'seller_authorize')
	pass

class itemcats():
	api='taobao.itemcats.get'
	def __init__(self):
		self.method=self.api
	def setParams(self,format='json',parent_cid='0',cids=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='features,modified_type,modified_time,cid,parent_cid,\
		name,is_parent,status,sort_order'
		return getRes(url)
	def parseItemCats(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'item_cats')
	pass

class item_props():
	api='taobao.itemprops.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',cid=None,pid=None,parent_pid=None):
		'''set app params,not all params covered'''
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='is_input_prop,type,modified_time,modified_type,pid,\
			parent_pid,parent_vid,name,is_key_prop,is_sale_prop,\
			is_color_prop,is_enum_prop,is_item_prop,must,multi,\
			prop_values,status,sort_order,child_template,is_allow_alias'
		url=getURL(d)
		return getRes(url)
	def parseItemProps(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'item_props')

class item_propvalues():
	api='taobao.itempropvalues.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',cid=None,pvs=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='modified_time,modified_type,cid,pid,prop_name,\
			vid,name,name_alias,is_parent,status,\
			sort_order'
		url=getURL(d)
		return getRes(url)
	def parseItemPropValues(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'prop_values')
	pass

class shop_cats():
	api='taobao.shopcats.list.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		self.fields='cid,parent_cid,name,is_parent'
		d={k:v for k,v in self.__dict__.items() if v!=None}
		url=getURL(d)
		return getRes(url)
	def parseShopCats(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'shop_cats')
	pass

def main():
	pass

if __name__=='__main__':
	main()
	pass
